<?
include 'order_head.php'
?>
<h2 class="headSection">รายการสินค้า</h2>
<table cellpadding="6" cellspacing="1"  border="0" class="myTable table2">

<tr>
  
  <th style="width:55%">สินค้า</th>
  
  <th style="text-align:center;width:10%">ราคาต่อหน่วย</th>
  <th style="text-align:center;width:10%">หน่วย</th>
  <th style="text-align:center;width:10%">จำนวน</th>
  <th style="text-align:center;width:10%">มูลค่า</th>
  
  
</tr>

<?php $i = 1; ?>
<?
$allDiscount = 0;
$totalSale = 0;
$totalPremium = 0;
?>
<?php foreach ($this->cart->contents() as $items): ?>

	<?
	
	$option = $this->cart->product_options($items['rowid']);
	
	$option = (array)$option;
	$pID = $option['MATNR'];
	$pName = $option['MAKTX'];
	$baseUnit = $option['BASE_UNIT'];
	if($baseUnit=="KAR"){
		$b = "ลัง";
	}else if($baseUnit=="PAK"){
		$b = "แพ็ก";
	}else {
		$b = "ชิ้น";
	}
	?>
	<?
	$class="";
	
	if(isset($option['ISPremium'])){
		if($option['ISPremium']=="Yes"){
			$class = "line-preimum";
			$totalPremium+=$items['subtotal'];
			$pName = $pName."<br>(สินค้าแถม)";	
		}
		
	}else{
		$totalSale+=$items['subtotal'];
	}
	?>
	<tr class="<?php echo $class?>">
		
	  <td style="width:40%"><?php echo $pID ?><br />
		<?php echo $pName ?></td>
	
		
	<td style="width:10%;text-align: right;"><?php echo number_format( $items['price'],2)?></td>	 
		<td style="width:20%;text-align: center;"><?php echo $b ?></td>
	<td style="width:10%;text-align: right;"><?php echo converUnit($items,$option);?></td>
		<td style="text-align:right;width:60px">
	  		<?php echo number_format($items['subtotal'],2)?>
	  </td> 
	</tr>
<?php $i++; ?>

<?php endforeach; ?>

<tr>
  <td colspan="3"> </td>
  <td class="right"><strong>ราคารวม</strong></td>
  
  <td class="right" style="text-align: right"><?php echo $this->cart->format_number($totalSale); ?></td>
</tr>
<tr>
  <td colspan="3"> </td>
  <td class="right"><strong>ราคาของแถม</strong></td>
  
  <td class="right" style="text-align: right"><?php echo $this->cart->format_number($totalPremium); ?></td>
</tr>
<tr>
  <td colspan="3"> </td>
  <td class="right"><strong>ส่วนลด</strong></td>
  <td class="right" style="text-align: right"><?php echo $this->cart->format_number($discount); ?></td>
</tr>
<tr>
  <td colspan="3"> </td>
  <td class="right"><strong>สุทธิ</strong></td>
  <td class="right" style="text-align: right"><?php echo $this->cart->format_number($totalSale - $discount); ?></td>
</tr>
</table>
<br /> 

<h2 class="headSection">จัดส่งสินค้า</h2>
<table cellpadding="6" cellspacing="1"  border="0" class="myTable table2">

<tr>
  
  <th style="width:45%">สินค้า</th>
  <th style="text-align:center;width:10%">จำนวน</th>

  <th style="text-align:right;width:10%">มูลค่า</th>
  
</tr>

<?php $i = 1; ?>
<?
$allDiscount = 0;
$totalSale = 0;
$totalPremium = 0;
$firstSendPrice  = 0;
$premiumPrice = 0;
?>
<?php foreach ($this->cart->contents() as $items): ?>

	<?
	
	$option = $this->cart->product_options($items['rowid']);
	
	$option = (array)$option;
	$pID = $option['MATNR'];
	$pName = $option['MAKTX'];
	$baseUnit = $option['BASE_UNIT'];
	if($baseUnit=="KAR"){
		$b = "ลัง";
	}else if($baseUnit=="PAK"){
		$b = "แพ็ก";
	}else {
		$b = "ชิ้น";
	}
	?>
	<?
	$class="";
	$pType = "sale";
	if(isset($option['ISPremium'])){
		if($option['ISPremium']=="Yes"){
			$class = "line-preimum";
			$totalPremium+=$items['subtotal'];
			$pName = $pName."<br>(สินค้าแถม)";
			$pType = "premium";	
		}
		
	}else{
		$totalSale+=$items['subtotal'];
	}
	$sendQty = $items['qty'] - ($items['qty'] - $DI[$i-1]['pQty']);
	
	$sendPrice = $sendQty * $items['price'];
	if($sendQty > 0 && $pType=="sale" ){
		$firstSendPrice+= $sendPrice;
	}else if($sendQty > 0 && $pType=="premium" ){
		$premiumPrice+= $sendPrice;
	}	
	
	
	if($sendQty > 0 ){
	?>
	<tr class="<?php echo $class?>">
		
	  <td style="width:40%"><?php echo $pID ?><br />
		<?php echo $pName ?></td>
		<?
		$items['qty'] = $sendQty;
		?>
		<td style="width:10%;text-align: right;"><?php echo converUnit($items,$option);?></td>
		 
		
	   <td style="text-align:right;width:60px">
	  	<div style="width:60px;float:right;">
	  		<?php echo number_format($sendPrice,2) ?>
	  		</div>
	  </td>
	  
	  
	  
	</tr>

<?php }
$i++; ?>

<?php endforeach; ?>

<tr>
  <td colspan="1"> </td>
  <td class="right"><strong>ราคารวม</strong></td>
  
  <td class="right" style="text-align: right"><?php echo $this->cart->format_number($firstSendPrice,2 ); ?></td>
</tr>
<tr>
  <td colspan="1"> </td>
  <td class="right"><strong>ราคาของแถม</strong></td>
  
  <td class="right" style="text-align: right"><?php echo $this->cart->format_number($premiumPrice); ?></td>
</tr>
<tr>
  <td colspan="1"> </td>
  <td class="right"><strong>ส่วนลด</strong></td>
  <td class="right" style="text-align: right"><?php echo $this->cart->format_number($discount); ?></td>
</tr>
<tr>
  <td colspan="1"> </td>
  <td class="right"><strong>สุทธิ</strong></td>
  <td class="right" style="text-align: right"><?php echo $this->cart->format_number(($firstSendPrice) - $discount); ?></td>
</tr>

</table>
<br /> 
<h2>วิธีการชำระเงิน</h2>
<?

?>
<ul>
	<li>สถานะการชำระเงิน: <?php echo ($paymentStatus=="Y") ? "ชำระเงินเรียบร้อยแล้ว" : "ยังไม่ได้ชำระเงิน"?></li>
	<li>วันที่จัดส่ง: <?php echo $shipDate?></li>
	<?
	if($_POST['cash_amount'] > 0 ){
	?>
	<li>เงินสด จำนวนเงิน <?php echo number_format($_POST['cash_amount'],2)?> บาท </li>
	<?
	}
	?>
	<?
	if($_POST['amount_cheque'] > 0 ){
	?>
	<li>เช็ค จำนวนเงิน <?php echo  number_format($_POST['amount_cheque'],2)?> บาท ต้องชำระเงินผ่านบัญชีธนาคาร <?php echo $_POST['bank_cheque']?> สาขา <?php echo $_POST['branch_cheque']?> ลงวันที่ <?php echo $_POST['date_cheque']?></li>
	<?
	}
	?>
	<?
	if($_POST['amount_trans'] > 0 ){
	?>
	<li>โอน จำนวนเงิน <?php echo number_format($_POST['amount_trans'],2)?> บาท ต้องชำระเงินผ่านบัญชีธนาคาร <?php echo $_POST['bank_trans']?> สาขา <?php echo $_POST['branch_trans']?> ลงวันที่ <?php echo $_POST['date_trans']?></li>
	<?
	}
	?>
</ul>
<br />
<a class="btn-default" href="<?php echo base_url()?>order/payment/"><i class="fa fa-chevron-left"></i> ข้อมูลชำระเงิน</a>
<a class="btn-next" href="<?php echo base_url()?>order/createOrder/"><i class="fa fa-check"></i> ยืนยัน</a>
